package define

import (
	"time"

	kadefine "kiwi/actor/define"
	katimer "kiwi/actor/timer"
	kawork "kiwi/actor/work"
)

// IWorker 供Super子类调用的接口
type IWorker interface {
	PID() *kadefine.PID

	Start(ctx kadefine.Context, name string, startFunc func() error, wait bool) (err error)
	HasStart() bool
	Started() bool
	Stop(stopFunc func(), wait bool) error
	HasStop() bool

	Post(work kawork.IPostWork) error
	Dispatch(timeout time.Duration, work kawork.IDispatchWork) error

	NewTimer(dur time.Duration, tag katimer.Tag, cb katimer.Callback) katimer.ID
	NewLoopTimer(dur time.Duration, tag katimer.Tag, cb katimer.Callback) katimer.ID
	StopTimer(id katimer.ID) error
}

// IWorkerImplement 供Worker调用的接口
type IWorkerImplement interface {
	Destroy()

	OnStarted(ctx kadefine.Context)
	OnStopping(ctx kadefine.Context)
	OnStopped(ctx kadefine.Context)
	OnReceiveMessage(ctx kadefine.Context)
	OnActorTerminated(who *kadefine.PID, ctx kadefine.Context)
	OnRestarting(ctx kadefine.Context)
	OnRestarted(ctx kadefine.Context)

	BeforeTriggerTimer(id katimer.ID, tag katimer.Tag, ctx kadefine.Context) (ok bool, err error)
	AfterTriggerTimer(err error, id katimer.ID, tag katimer.Tag, ctx kadefine.Context)
}
